﻿using System;

namespace YArchitech.MEP
{
	public class HYTerminal : HYComponent, IHasHostTube
	{
		public double Resistance { get; set; }

		public double PressureDrop { get; set; }

		public double DynamicPressure { get; set; }

		public HYTube GetHostTube()
		{
			HYComponent previous = base.Previous;
			while (previous != null && !(previous is HYTube))
			{
				previous = previous.Previous;
			}
			if (previous == null)
			{
				return null;
			}
			return previous as HYTube;
		}

		public override void AllocateFlow()
		{
		}

		public override void Cal(HYSystemOption op)
		{
			base.Cal(op);
			this.AttachResistanceToTube();
		}

		public virtual void AttachResistanceToTube()
		{
			HYTube hostTube = this.GetHostTube();
			if (hostTube != null)
			{
				hostTube.AddAttachment(this, this.Name, this.Resistance, 0);
			}
		}
	}
}
